<script type="text/javascript">
    var searchProperty = "<?php echo $searchProperty;?>";
    var searchField = "<?php echo $searchField;?>";
    var searchText = "<?php echo $searchText;?>";
    var catalogId = "<?php echo $catalogId;?>";
    var subCatalogId = "<?php echo $subCatalogId;?>";
    var contentTypeId = "<?php echo $contentTypeId;?>";
    function checkAll(){
       var checkall=document.getElementsByName('check_all');
       for(var i=0;i<checkall.length;i++)
       {
          checkall[i].checked=true;
       }
    }
    function checkInvert(){
       var checkall=document.getElementsByName('check_all');
       for(var i=0;i<checkall.length;i++)
       {
           if(checkall[i].checked)
                checkall[i].checked=false;
           else
                checkall[i].checked=true;
       }
    }
    function actionFun(content, actionType) {
        var confirmResult = false;
        //if(content == null && actionType)
        switch (actionType) {
            case "delete":
                confirmResult = confirm('确定要删除？');
                break;
            case "publish":
                confirmResult = confirm('确定要发布？');
                break;
            case "cancelPublish":
                confirmResult = confirm('确定要取消发布？');
                break;
            case "cancelTop":
                confirmResult = confirm('确认要取消置顶？');
                break;
            case "top":
                confirmResult = confirm('确认要置顶？');
                break;
            case "recommend":
                confirmResult = confirm('确认要推荐？');
                break;
            case "cancelRecommend":
                confirmResult = confirm('确认要取消推荐？');
                break;
            case "cancelFocus":
                confirmResult = confirm('确认要取消焦点？');
                break;
        }
        if (actionType == "search")
            confirmResult = true;
        if (confirmResult) {
            if (1 == content && actionType != "search") {
                var checkall = document.getElementsByName('check_all');
                content = "";
                for (var i = 0; i < checkall.length; i++) {
                    if (checkall[i].checked)
                        content += checkall[i].value + " ";
                }
            }
            if (catalogId != "")
                content += "&catalogId=" + catalogId;
            if (subCatalogId != "")
                content += "&subCatalogId=" + subCatalogId;
            if (contentTypeId != "")
                content += "&contentTypeId=" + contentTypeId;
            if (actionType == "search") {
                if ($("#sSearchProperty").val() != "none")
                    content += "&searchProperty=" + $("#sSearchProperty").val();
                if ($("#sSearchField").val() != "none")
                    content += "&searchField=" + $("#sSearchField").val();
                var searchCondition = $.trim($("#txtSearch").val());
                if (searchCondition != "") {
                    content += "&searchText=" + searchCondition;
                }
            }
            window.location = "<?php echo url_for("album/index?submitType=");?>" + actionType + "&content=" + content;
        }
    }
    function editInfo(content){
        location="<?php echo url_for("album/edit?albumEdit=1&content=");  ?>"+content;
    }
    $(document).ready(function() {
        if (searchProperty != "")
            $("#sSearchProperty").val(searchProperty);
        if (searchField != "")
            $("#sSearchField").val(searchField);
        $("#txtSearch").val(searchText);
    });
</script>
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="padding-right:10px;">
    <tr>
        <td style="height:30px;">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td>位置：<?php echo $navigator;?></td>
                    <td></td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td style="height:30px;">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td><input id="add" type="button"
                               onclick="window.location='<?php echo url_for("album/add?catalogId=" . $sf_request->getParameter("catalogId"));  ?>';"
                               value="添加美图"/>

                        <input id="del" type="button" onclick="actionFun(1,'delete');" value="删除美图"/></td>
                    <td align="right">搜索：
                        <select name="sSearchProperty" id="sSearchProperty" onchange="actionFun(null,'search')">
                            <option value="none">不限属性</option>
                            <option value="top">置顶</option>
                            <option value="recommend">推荐</option>
                            <option value="focus">焦点</option>
                            <option value="publish">发布</option>
                            <option value="delete">删除</option>
                        </select>
                        <input name="txtSearch" type="text" id="txtSearch"/>
                        <select name="sSearchField" id="sSearchField" onchange="actionFun(null,'search')">
                            <option value="none">不限字段</option>
                            <option value="title">相册名称</option>
                            <option value="keyword">关键字</option>
                            <option value="tag">Tag 值</option>
                        </select>
                        <input name="btnSearch" type="button" id="btnSearch" value="搜索"
                               onclick="actionFun(null,'search')"/></td>
                </tr>
            </table>

        </td>
    </tr>
    <tr>
        <td>
        <?php
                //echo $aaa;
        echo "<table cellspacing=0' cellpadding='4' border='1' style=\"width:100%;color:#333333;border-collapse:collapse;\"><tr style=\"color:White;background-color:#5D7B9D;font-weight:bold;height:25px;\"><td style=\"width:50px;\" align=\"center\">ID</td><td style=\"width:30px;\" align=\"center\">选择</td><td align=\"center\">标题</td><td style=\"width:100px;\" align=\"center\">发布者</td><td style=\"width:70px;\" align=\"center\">点击率</td><td style=\"width:80px;\" align=\"center\">状态</td><td style=\"width:80px;\" align=\"center\">发布时间</td><td style=\"width:70px;\" align=\"center\">操作</td><td align='center' style=\"width:40px;\">预览</td></tr>";
        $photoGroups = @$pages->getResults();
        $i = 0;
        foreach($photoGroups as $row=>$photoGroup)
        {
            $photoGroupTypeStr = "";
            if ($photoGroup->getIsOnTopB())
                $photoGroupTypeStr = $photoGroupTypeStr . " [置顶]";
            if ($photoGroup->getIsRecommendB())
                $photoGroupTypeStr = $photoGroupTypeStr . " [荐]";
            if ($photoGroup->getIsFocusB())
                $photoGroupTypeStr = $photoGroupTypeStr . " [焦]";
            //id,title,发布者，发布时间，（编辑，删除）image_tag('edit.png')
            if ($i % 2 == 0)
                $trStyle = "style=\"color:#333333;background-color:#F7F6F3;height:30px;\"";
            else
                $trStyle = "style=\"color:#284775;background-color:White;height:30px;\"";
            echo "<tr ".$trStyle."><td>".$photoGroup->getPhoto_group_id()."</td><td align=\"center\"><input type='checkbox' name='check_all' value='"
                       .$photoGroup->getPhoto_group_id()."' /></td><td>".link_to($photoGroup->getTitle().$photoGroupTypeStr,"album/edit?albumEdit=1&content=".$photoGroup->getPhoto_group_id(),"")
                       ."</td><td>admin</td><td>".$photoGroup->getHit_i()."</td><td>".$photoGroup->getStatus()->getName()."</td><td align=\"center\">".date('Y/m/d',strtotime($photoGroup->getCreate_time()))
                       ."</td><td align=\"center\"><img border='0' title='编辑' src='/sfDoctrinePlugin/images/edit.png'onclick='editInfo(".$photoGroup->getPhoto_group_id().");' style='cursor:pointer;' />"
                       ."<img border='0' title='删除' src='/sfDoctrinePlugin/images/delete.png'onclick='actionFun(".$photoGroup->getPhoto_group_id(). ",\"delete\");' style='cursor:pointer;' />"
            . "</td><td align='center'><a href='/index.php/album/detail?photoGroupId=" . $photoGroup->getPhotoGroupId() . "' target='_blank'>预览</a></td></tr>";
            $i++;
        }
        echo "</table>";
        $numPages = $pages->getLastPage();
        $CurrentPageID = $pages->getPage();
        if (@$pages->haveToPaginate()) {
            $str = $CurrentPageID - 6;
            $end = $CurrentPageID + 5;
            if ($str < 0)
                $str = 0;
            if ($end > $numPages)
                $end = $numPages;
            echo "<div class='page_list'>";
            $catalogStr = "";
            if ($contentTypeId != null)
                $catalogStr = "&contentTypeId=" . $contentTypeId;
            if ($catalogId != null)
                $catalogStr = $catalogStr . "&catalogId=" . $catalogId;
            if ($subCatalogId != null)
                $catalogStr = $catalogStr . "&subCatalogId=" . $subCatalogId;
            if ($searchStr != "")
                $catalogStr = $catalogStr . $searchStr;
            if ($CurrentPageID > 1)
                echo link_to("首页", "album/index?currentPage=1" . $catalogStr) . link_to("上一页", "album/index?currentPage=" . ($CurrentPageID - 1) . $catalogStr);

            for ($i = $str; $i < $end; $i++)
            {
                if ($i == ($CurrentPageID - 1)) {
                    echo "<a class='now02' href='#'>" . ($i + 1) . "</a>";
                }
                else {
                    echo link_to(($i + 1), "album/index?currentPage=" . ($i + 1) . $catalogStr);
                }
            }

            if ($CurrentPageID < $numPages)
                echo link_to("下一页", "album/index?currentPage=" . ($CurrentPageID + 1) . $catalogStr) . link_to("末页", "album/index?currentPage=" . $numPages . $catalogStr);
            echo "</div>";
        }
        ?>
        </td>
    </tr>
    <tr>
        <td valign="middle" style="height:30px;">
            <input type='button' onclick='checkAll();' value='全选'/> <input type='button' onclick='checkInvert();'
                                                                           value='反选'/> <input type='button'
                                                                                               onclick='actionFun(1,"publish");'
                                                                                               value='发布'/> <input
                type='button' onclick='actionFun(1,"cancelPublish");' value='取消发布'/> <input type='button'
                                                                                            onclick='actionFun(1,"recommend");'
                                                                                            value='推荐'/> <input
                type='button' onclick='actionFun(1,"cancelRecommend");' value='取消推荐'/> <input type='button'
                                                                                              onclick='actionFun(1,"top");'
                                                                                              value='置顶'/> <input
                type='button' onclick='actionFun(1,"cancelTop");' value='取消置顶'/> <input type='button'
                                                                                        onclick='actionFun(1,"cancelFocus");'
                                                                                        value='取消焦点'/></td>
    </tr>
    <tr>
        <td>

        </td>
    </tr>
</table>
